
package com.bi2.events.mobile;

import java.util.ArrayList;
import java.util.Date;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.os.Bundle;

import com.bi2.events.mobile.adapters.AmigosAdapter;
import com.bi2.events.mobile.entities.Usuario;

public class AmigosTabActivity extends ListActivity {

    private ProgressDialog m_ProgressDialog = null;
    private ArrayList<Usuario> m_usuarios = null;
    private AmigosAdapter m_adapter;
    private Runnable viewAmigos;
    private Runnable returnRes = new Runnable() {

        public void run() {
            if (m_usuarios != null && m_usuarios.size() > 0) {
                m_adapter.notifyDataSetChanged();
                for (int i = 0; i < m_usuarios.size(); i++)
                    m_adapter.add(m_usuarios.get(i));
            }
            m_ProgressDialog.dismiss();
            m_adapter.notifyDataSetChanged();
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.perfil_amigos_tab);

        ArrayList<Usuario> m_amigos = new ArrayList<Usuario>();
        this.m_adapter = new AmigosAdapter(this, R.layout.perfil_amigos_row, m_amigos);
        setListAdapter(this.m_adapter);

        viewAmigos = new Runnable() {
            public void run() {
                getUsuarios();
            }
        };
        Thread thread = new Thread(null, viewAmigos, "MagentoBackground");
        thread.start();
        m_ProgressDialog = ProgressDialog.show(AmigosTabActivity.this, "Aguarde...",
                "Carregando dados...", true);
    }

    private void getUsuarios() {
        try {
            m_usuarios = new ArrayList<Usuario>();
            Usuario o1 = new Usuario();
            o1.setNome("Caio");
            o1.setDtNasc(new Date(1890, 05, 20));
            Usuario o2 = new Usuario();
            o2.setNome("Jesus");
            o2.setDtNasc(new Date(2000, 01, 01));
            m_usuarios.add(o1);
            m_usuarios.add(o2);
            Thread.sleep(2000);
        } catch (Exception e) {
        }
        runOnUiThread(returnRes);
    }
}
